package com.ruoyi.factory.bom.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.factory.bom.domain.ProductCost;
import com.ruoyi.factory.bom.service.IProductCostService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品成本Controller
 * 
 * @author ruoyi
 * @date 2022-10-23
 */
@RestController
@RequestMapping("/system/productCost")
public class ProductCostController extends BaseController
{
    @Autowired
    private IProductCostService productCostService;

    /**
     * 查询产品成本列表
     */
    @PreAuthorize("@ss.hasPermi('system:productCost:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductCost productCost)
    {
        startPage();
        List<ProductCost> list = productCostService.selectProductCostList(productCost);
        return getDataTable(list);
    }

    /**
     * 导出产品成本列表
     */
    @PreAuthorize("@ss.hasPermi('system:productCost:export')")
    @Log(title = "产品成本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductCost tProductCost)
    {
        List<ProductCost> list = productCostService.selectProductCostList(tProductCost);
        ExcelUtil<ProductCost> util = new ExcelUtil<ProductCost>(ProductCost.class);
        util.exportExcel(response, list, "产品成本数据");
    }

    /**
     * 获取产品成本详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:productCost:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(productCostService.selectProductCostById(id));
    }

    /**
     * 新增产品成本
     */
    @PreAuthorize("@ss.hasPermi('system:productCost:add')")
    @Log(title = "产品成本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductCost tProductCost)
    {
        return toAjax(productCostService.insertProductCost(tProductCost));
    }

    /**
     * 修改产品成本
     */
    @PreAuthorize("@ss.hasPermi('system:productCost:edit')")
    @Log(title = "产品成本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductCost tProductCost)
    {
        return toAjax(productCostService.updateProductCost(tProductCost));
    }

    /**
     * 删除产品成本
     */
    @PreAuthorize("@ss.hasPermi('system:productCost:remove')")
    @Log(title = "产品成本", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(productCostService.deleteProductCostByIds(ids));
    }
}
